#region Using directives
using System;
using System.Data ;
using WP.DB;
using WP.MF.DataEntity; 
using WP.Commons ;
 #endregion
namespace WP.MF.DataAccess
{

	/*
	 * Created by SmartCreateCode Tool
	 * At 4/22/2005
	 */

    public class MProvinceDAL : IDataAccess
	{
		public MProvinceDAL()
		{
		}

        #region Select List
        public string SQLList(int iParameter)
        {
            string strSQL = @"SELECT RecID, ProvNo, ProvName From mProvince ORDER BY ProvNo ";
            return strSQL;
        }
        #endregion

		#region Fields
		private string Fields 
		{
			get
			{
                return @"ProvNo, ProvName,GstPct, PstPct, PstOnGst,TaxCode,Country,PstAcctno,PstProfitno, PstBranchNo,
                GstAcctno, GstProfitno,GstBranchNo,HomogeneousTax, TaxNeedConsiderDisc, EcoAcctno, EcoProfitno, CutoffSurchgAmt,
                RecyclingFeeAcctNo,RecyclingFeeProfitNo,RecyclingFeeBranchNo,DepositAcctNo,DepositProfitNo,DepositBranchNo,CollectSalesTax";
			}
		}
		#endregion

        #region	SelectDataByRecID
        public MProvinceDEL SelectDataByRecID(DBAccess dBAccess, string strRecId)
		{
            MProvinceDEL mProvinceDEL = new MProvinceDEL();
			
			string strSql= "";

			strSql="SELECT "+Fields+",RecId,RecStamp FROM mProvince ";
			
			if(strRecId !="" && int.Parse(strRecId)>=0)
			{
				strSql+=" WHERE RecId="+strRecId;
			}

            dBAccess.GetDataSet(strSql, MProvinceDEL.TABLENAME_MPROVINCE, mProvinceDEL);
            return mProvinceDEL;
		}
		#endregion	

		#region Select for look up
		public string SelectMProvinceForLookUp()
		{
			return "SELECT ProvNo, ProvName,RecID From mProvince";
		}
		#endregion

		#region Select by Key
		public MProvinceDEL SelectMProvinceByKey(DBAccess dBAccess, int iRecID)
		{
			MProvinceDEL mProvinceDEL=new MProvinceDEL();
			string strSql=string.Empty;
			object[] oValues;

			strSql=@"SELECT RecID,ProvNo,ProvName,PstPct,PstOnGst,
				Country,TaxCode,GstLabel,PstAcctno,PstProfitno,
				PstBranchno,GstAcctno,GstBranchno,GstProfitno,GstPct,
				PstLabel,EcoAcctno,EcoBranchno,EcoProfitno,HomogeneousTax,recstamp  FROM MProvince
				WHERE RecID={0}";

			oValues=new object[1];
			oValues[0]=iRecID;
			strSql=string.Format(strSql,oValues);
			dBAccess.GetDataSet(strSql,MProvinceDEL.TABLENAME_MPROVINCE,mProvinceDEL);
			return mProvinceDEL;
		}
		#endregion

		#region Insert table by DataRow
		public void InsertMProvince(DBAccess dBAccess,MProvinceDEL mProvinceDEL)
		{
			string strSql=string.Empty;
			DataRow dr=mProvinceDEL.Tables[0].Rows[0];

			strSql=BaseFunctions.GenerateSqlForDataAccess(  Fields,MProvinceDEL.TABLENAME_MPROVINCE,dr,FormStatus.AddNew );
			
			dr[MProvinceDEL.RECID]=dBAccess.GetObjectValue(strSql);
		}
		#endregion

		#region Update MProvince
		public void UpdateMProvince(DBAccess dBAccess,MProvinceDEL mProvinceDEL)
		{
			string strSql=string.Empty;
			DataRow dr=mProvinceDEL.Tables[0].Rows[0];
			strSql=BaseFunctions.GenerateSqlForDataAccess( Fields,MProvinceDEL.TABLENAME_MPROVINCE,dr,FormStatus.Update);
			
			dr[MProvinceDEL.RECSTAMP]=dBAccess.GetObjectValue(strSql);
		}
		#endregion

		#region Delete table by Key
		public void DeleteMProvince(DBAccess dBAccess,int iRecID)
		{
			string strSql=string.Empty;
            if (Customize.IsNuPro())
            {
                strSql = @"delete from mProvItemRecyclingFee where ProvNo in (select ProvNo from mProvince where RecID=" + iRecID + ")";
                dBAccess.ExecuteSql(strSql);
            }
			strSql=@"DELETE FROM mProvince WHERE RecID="+iRecID;
			dBAccess.ExecuteSql(strSql);
            
		}
		#endregion

        public void UpdateProvItemRecyclingFee(DBAccess dBAccess, DataRow dr)
        {
            string strSql = "";
            strSql = BaseFunctions.GenerateSqlForDataAccess("ProvNo,ItemNo,PackageSize,UnitRecyclingRate,FeeAmt,Unit,UnitDepositRate,DepositAmt", "mProvItemRecyclingFee", dr, FormStatus.Update);
            dr["RECSTAMP"] = dBAccess.GetObjectValue(strSql);
        }

        public void InsertProvItemRecyclingFee(DBAccess dBAccess, DataRow dr)
        {
            string strSql = "";
            strSql = BaseFunctions.GenerateSqlForDataAccess("ProvNo,ItemNo,PackageSize,UnitRecyclingRate,FeeAmt,Unit,UnitDepositRate,DepositAmt", "mProvItemRecyclingFee", dr, FormStatus.AddNew);
            dr["RecID"] = dBAccess.GetValue(strSql);
        }

        public void DeleteProvItemRecyclingFee(DBAccess dBAccess, int RecID)
        {
            string strSql = string.Empty;

            strSql = @"DELETE FROM mProvItemRecyclingFee WHERE RecID=" + RecID.ToString();
            dBAccess.ExecuteSql(strSql);
        }
	}
}